<html>
<head>
    <script src="../tma.js"></script>
    <script>
        tma.onload = function () {
            var screen = new TmaScreen(320, 320);
            screen.attachTo(TmaScreen.BODY);
            screen.x = 500 * Math.random() - 250;
            screen.y = 500 * Math.random() - 250;
            screen.z = 500 * Math.random() - 250;
            screen.h = 0;
            screen.w = 0;
            screen.afterimage("rgba(0, 0, 0, 0.5)");
            screen.blur(1, 0.95, 1.1, 0, 0, false);
            screen.sin = Math.sin;
            screen.cos = Math.cos;
            screen.update = function () {
                var x = this.x;
                var y = this.y;
                var z = this.z;
                var h = this.h;
                var w = this.w;
                for (var i = 0; i < 10000; i++) {
                    var absz = (z < 0)? -z: z;
                    if (absz < 0.00001)
                        z = 0.00001;
                    var vx = -10 * x + 10 * y;
                    var vy = 28 * x - y - x * z;
                    var vz = x * y - 8 / 3 * z;
                    x += vx / 1000;
                    y += vy / 1000;
                    z += vz / 1000;
                    var scale = 0.15;
                    var sz = 1 + z / 1000;
                    w += 0.00001;
                    var sin = this.sin(w);
                    var cos = this.cos(w);
                    var rx = x * cos - y * sin;
                    var ry = x * sin + y * cos;
                    var sx = (((160 + rx / scale) / sz) >> 0) % 320;
                    var sy = (((160 + ry * cos / scale) / sz) >> 0) % 320;
                    h += 0.0005;
                    this.addPixel(sx, sy, (h % 360) >> 0, 1, 0.05, 0xff, true);
                }
                this.x = x;
                this.y = y;
                this.z = z;
                this.h = h;
                this.w = w;
            };

            function main () {
                var _screen = screen;
                _screen.lock(TmaScreen.LOCK_WITH_SCREEN);
                _screen.update();
                _screen.unlock();
            }

            setInterval(main, 20);
        };
    </script>
</head>
</html>
